package com.kust.smarthome.web.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kust.smarthome.web.model.DeviceState;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface DeviceStateMapper extends BaseMapper<DeviceState> {

    @Insert("insert into device_state values id=null,is_update=0,type_id=#{typeId},device_id=#{deviceId},operation=#{operation}")
    boolean insertDevicestate(Integer typeId, Integer deviceId, String operation);

    @Select("select id,is_update,type_id,device_id,operation from device_state where device_id=#{deviceId} and type_id=#{typeId} and is_update=0")
    List<DeviceState> getOperationList(Integer deviceId, Integer typeId);

    @Update("update device_state set is_update=1 where id=#{id}")
    boolean changeUpdate(Integer id);

}
